import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk
from 数据中心 import Dcenter
from mandbrot import Mandbrot


da = Dcenter()
root = tk.Tk()
tk.Button(root, text="Quit", command=root.destroy).pack()

# sw = root.winfo_screenwidth()
# sh = root.winfo_screenheight()
# da.sw, da.sh = sw, sh

root.wm_title("chen设计的Mandelbrot分形图{0:d}x{1:d}".format(da.sw, da.sh))
# root.geometry("1024x728+20+20")
root.state("zoomed")    # 最大化
root.resizable(width=False, height=False)

lb = tk.Listbox(root, selectmode=tk.SINGLE, font=("Code font", 14, "bold"), width=14, fg='#66e8e4', bg='#224466')
lb.pack(side=tk.LEFT, fill='y')
for ci in da.cmaps:
    lb.insert(tk.END, ci)

# 创建matplotlib窗口
fig= plt.figure(dpi=96, 
                figsize=((da.sw-2*da.margin)/96, (da.sh-2*da.margin)/96), 
                facecolor=da.bk/2)

canvas = FigureCanvasTkAgg(fig, master=root)    # tkinter接管

# 画图
# koch = Koch()
mdb = Mandbrot(da)

# 更改颜色
def calllistbox(event):
    it = lb.curselection()[0]
    str1 = lb.get(it)
    plt.set_cmap(str1)
    mdb.CurCmap = str1
    canvas.draw()
lb.bind('<Double-Button-1>', calllistbox)


canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
root.mainloop()